#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
struct Edge {
    int x, y;
} E[] = {
        {1, 2},
        {1, 3},
        {1, 5},
        {2, 4},
        {4, 5},
        {4, 2}

};
int Vertex[5] = {1, 2, 3, 4, 5};
int ind[6], outd[6];
int n = 5, m = 5;

bool topsort() {
    int cnt = 0;
    queue<int> Q;
    for (int i = 1; i <= n; i++) {
        if (ind[i] == 0) {
            Q.push(i);
        }
    }
    while (!Q.empty()) {
        int temp = Q.front();//如果是优先队列，这里可以是top()
        cout << "->" << temp;
        Q.pop();
        ++cnt;
        for (auto e:E) {
            if (e.x == temp) {
                ind[e.y]--;
                if (ind[e.y] == 0) {
                    Q.push(e.y);

                }
            }
        }
    }

    cout << endl;
    return cnt == 5;

}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    for (auto e:E) {
        outd[e.x]++;
        ind[e.y]++;
    }
    copy(ind + 1, ind + 6, ostream_iterator<int>(cout, " "));
    cout << endl;
    copy(outd + 1, outd + 6, ostream_iterator<int>(cout, " "));
    cout << endl;
    cout << topsort() << endl;
    return 0;
}
